package com.shao.onlinepdf.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Optional;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.shao.onlinepdf.entity.TStyle;
import com.shao.onlinepdf.service.ITImagesService;
import com.shao.onlinepdf.service.ITStyleService;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;

/**
 *
 * @author shaohuailin
 * @date 2021/09/06
 */
@RestController
@RequestMapping("/images")
public class ImagesController {
    
    @Autowired
    private ITImagesService imagesService;
    
    @GetMapping("/{id}")
    public void id(@PathVariable String id, HttpServletResponse response) throws IOException {
        response.setContentType("image/jpeg");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(80, 25, 4, 4);
        BufferedImage image = captcha.getImage();
        ImageIO.write(image, "jpg", response.getOutputStream());
    }
}
